package com.bb.flow.service.imp.node;

import com.bb.flow.api.ConditionValueCalc;
import com.bb.flow.api.ExpressionCalc;
import com.bb.flow.api.entries.ConditionResult;
import com.bb.flow.api.entries.FlowContext;
import com.bb.flow.config.enumtype.DataType;

/**
 * @author bigbeard on 2020-02-27
 */
public class JudgeBase implements ExpressionCalc, ConditionValueCalc {
    /**
     * 结果条件条件判断
     *
     * @param flowNodeData  流程上下文参数
     * @return true:传入的条件成功,false:条件不成立
     */
    @Override
    public ConditionResult calcExpress(FlowContext flowNodeData) {
        System.out.println(this.toString() + ":::calcExpress");
        ConditionResult result = new ConditionResult();
        result.setResult(true);
        result.setDataType(DataType.BOOLEAN);
        return result;
    }

    /**
     * 计算表达式
     *
     * @param expression              表达式

     * @param flowNodeData            当前流程上下文信息
     * @param conditionNodeValueInfos 条件值结果
     * @return true 满足条件,false 不满足条件
     */
    @Override
    public boolean calc(String expression, FlowContext flowNodeData, ConditionResult conditionNodeValueInfos) {
        System.out.println(this.toString() + ":::calc");
        return !(Math.random() * 100 > 50);
    }

}
